from selenium.webdriver.common.by import By
from base.base_action import BaseAction


# 角色权限管理页面
class RolePermissionManagePage(BaseAction):

    # 角色权限管理按钮
    role_permission_manage_btn = By.XPATH, "//span[text()='授权管理']"

    # 搜索角色
    keyword_search = By.XPATH, "//input[@placeholder='搜索角色']"

    # 新增按钮
    add_btn = By.XPATH, "//span[text()='新增角色']"

    # 角色名称输入框
    role_name_input = By.XPATH, "//input[@placeholder='请输入角色名称']"

    # 角色说明输入框
    role_explain = By.CSS_SELECTOR, ".el-textarea__inner"

    # 授权类型
    promise_type = "document.getElementsByClassName('el-checkbox__input')[0].click();"

    # 功能复选框
    function_check_box = "document.getElementsByClassName('el-checkbox__inner')[6].click();"

    # 确定按钮
    determine_btn = "document.getElementsByClassName('el-button el-button--primary')[1].click();"

    # 管理用户
    manage_user_btn = "document.getElementsByClassName('operate-style')[0].click();"

    # 添加用户按钮
    add_user_btn = By.XPATH, "//span[text()='添加用户']"

    # 全选框
    select_all = "document.getElementsByClassName('el-checkbox__inner')[2].click();"

    # 设置授权范围按钮
    set_promise_scope = By.XPATH, "//span[contains(text(), '设置授权范围')]"

    # 选择部门
    select_dept = "document.getElementsByClassName('el-checkbox__inner')[14].click();"

    # 确定按钮
    determine_btn1 = "document.getElementsByClassName('el-button el-button--primary')[6].click();"

    # 复制角色
    copy_role = "document.getElementsByClassName('operate-style')[1].click();"

    # 全选,移除
    select_all1 = "document.getElementsByClassName('el-checkbox__inner')[0].click();"

    # 移除用户
    remove_user = By.XPATH, "//span[text()='移除用户']"

    # 删除角色
    remove_role = By.XPATH, "//span[contains(text(), '删除')]"

    # 确定按钮
    determine_btn2 = By.XPATH, "/html/body/div[2]/div/div[3]/button[2]"

    # 点击角色权限管理按钮
    def click_role_permission_manage_btn(self):
        return self.click(self.role_permission_manage_btn)

    # 输入关键字进行搜索
    def input_keyword_search(self, context):
        return self.input(self.keyword_search, context)

    # 点击新增按钮
    def click_add_btn(self):
        return self.click(self.add_btn)

    # 输入角色名称
    def input_role_name(self, context):
        return self.input(self.role_name_input, context)

    # 输入角色说明
    def input_role_explain(self, context):
        return self.input(self.role_explain, context)

    # 点击授权类型
    def click_promise_type(self):
        return self.execute_js(self.promise_type)

    # 点击功能复选框
    def click_function_check_box(self):
        return self.execute_js(self.function_check_box)

    # 点击确定按钮
    def click_determine_btn(self):
        return self.execute_js(self.determine_btn)

    # 点击管理用户
    def click_manage_user(self):
        return self.execute_js(self.manage_user_btn)

    # 点击添加用户
    def click_add_user_btn(self):
        return self.click(self.add_user_btn)

    # 点击全选
    def click_select_all(self):
        return self.execute_js(self.select_all)

    # 点击设置授权范围
    def click_set_promise_scope(self):
        return self.click(self.set_promise_scope)

    # 点击选择部门
    def click_select_dept(self):
        return self.execute_js(self.select_dept)

    # 点击确定按钮
    def click_determine_btn1(self):
        return self.execute_js(self.determine_btn1)

    # 点击复制角色
    def click_copy_role(self):
        return self.execute_js(self.copy_role)

    # 清空角色名称
    def clear_role_name_input(self):
        return self.clear(self.role_name_input)

    # 全选
    def click_select_all1(self):
        return self.execute_js(self.select_all1)

    # 点击移除
    def click_remove_user(self):
        return self.click(self.remove_user)

    # 点击删除按钮
    def click_remove(self):
        return self.click(self.remove_role)

    # 点击确定按钮
    def click_determine_btn2(self):
        return self.click(self.determine_btn2)




